package com.apes.fn.mdm.supplierConfiguration;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.car.model.CarLabel;
import com.apes.scm.pur.purchaseOrder.model.PurchaseOrderItem;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = SupplierBrand.CONST_TABLE_NAME)
public class SupplierBrand extends BaseModel {

    public static final String CONST_TABLE_NAME = "mas_supplier_brand";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "供应商厂牌")
    @Comment("编码")
    private String id;

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "supplier_susiness_scopee_id", referencedColumnName = "id")
    @Comment("供应商经营范围编码")
    private SupplierBusinessScope supplierBusinessScopeId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "carlabel_id", referencedColumnName = "id")
    @Comment("厂牌编码")
    private CarLabel carLabelId;

    // 以下字段给前端临时展示用
    @Transient
    private String carBrand;

    @Transient
    private String manufacturers;

    @Transient
    private String logo;

    public String getCarBrand() {
        return carBrand = this.carLabelId.getCarBrand();
    }

    public String getManufacturers() {
        return manufacturers = this.carLabelId.getManufacturers();
    }

    public String getLogo() {
        return logo = this.carLabelId.getLogo();
    }
}
